﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Foothill.Service.AdService;
using Foothill.Model;
using Foothill.Filter.Test.TestUtilities;

namespace Foothill.Service.Test
{
    [TestClass]
    public class ReorderServiceTest
    {
        private IReorderService _reorderService;

        [TestInitialize]
        public void Setup()
        {
            _reorderService = new ReorderService();
        }
        
        [TestMethod]
        public void OrderByPriceAsc()
        {
            ForSaleAd cheapCar = new ForSaleAd { AdId = 0, Price = 99 };
            ForSaleAd normCar = new ForSaleAd { AdId = 1, Price = 100 };
            ForSaleAd expensiveCar = new ForSaleAd { AdId = 2, Price = 101 };

            IList <ForSaleAd> reorderedList = _reorderService.ReorderSearchResultList(OrderByItems.ByPrice, Common.fhSortDirection.ASC, new List<ForSaleAd>() { normCar, cheapCar, expensiveCar });
            IList<ForSaleAd> expectedList = new List<ForSaleAd>() { cheapCar, normCar, expensiveCar };
            
            CollectionAssert.AreEqual(expectedList.ToArray(), reorderedList.ToArray(), new SimpleAdIdComparer());
        }

        [TestMethod]
        public void OrderByPriceDesc()
        {
            ForSaleAd cheapCar = new ForSaleAd { AdId = 0, Price = 99 };
            ForSaleAd normCar = new ForSaleAd { AdId = 1, Price = 100 };
            ForSaleAd expensiveCar = new ForSaleAd { AdId = 2, Price = 101 };

            IList<ForSaleAd> reorderedList = _reorderService.ReorderSearchResultList(OrderByItems.ByPrice, Common.fhSortDirection.DESC, new List<ForSaleAd>() { normCar, expensiveCar, cheapCar });
            IList<ForSaleAd> expectedList = new List<ForSaleAd>() { expensiveCar, normCar, cheapCar };

            CollectionAssert.AreEqual(expectedList.ToArray(), reorderedList.ToArray(), new SimpleAdIdComparer());
        }

        [TestMethod]
        public void OrderByKilometersAsc()
        {
            ForSaleAd lowMileageCar = new ForSaleAd { AdId = 0, MileAge = 99 };
            ForSaleAd normMileageCar = new ForSaleAd { AdId = 1, MileAge = 100 };
            ForSaleAd highMileageCar = new ForSaleAd { AdId = 2, MileAge = 101 };

            IList<ForSaleAd> reorderedList = _reorderService.ReorderSearchResultList(OrderByItems.ByKilometers, Common.fhSortDirection.ASC, new List<ForSaleAd>() { highMileageCar, lowMileageCar, normMileageCar });
            IList<ForSaleAd> expectedList = new List<ForSaleAd>() { lowMileageCar, normMileageCar, highMileageCar };

            CollectionAssert.AreEqual(expectedList.ToArray(), reorderedList.ToArray(), new SimpleAdIdComparer());
        }

        [TestMethod]
        public void OrderByKilometersDesc()
        {
            ForSaleAd lowMileageCar = new ForSaleAd { AdId = 0, MileAge = 99 };
            ForSaleAd normMileageCar = new ForSaleAd { AdId = 1, MileAge = 100 };
            ForSaleAd highMileageCar = new ForSaleAd { AdId = 2, MileAge = 101 };

            IList<ForSaleAd> reorderedList = _reorderService.ReorderSearchResultList(OrderByItems.ByKilometers, Common.fhSortDirection.DESC, new List<ForSaleAd>() { highMileageCar, lowMileageCar, normMileageCar });
            IList<ForSaleAd> expectedList = new List<ForSaleAd>() { highMileageCar, normMileageCar, lowMileageCar };

            CollectionAssert.AreEqual(expectedList.ToArray(), reorderedList.ToArray(), new SimpleAdIdComparer());
        }
    }
}
